package com.community.comsys.service.impl;

import java.util.List;

import com.community.common.utils.DateUtils;
import com.community.comsys.domain.Shop;
import com.community.comsys.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.community.comsys.domain.Community;
import com.community.comsys.service.ICommunityService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目管理Service业务层处理
 * 
 * @author 潇东
 * @date 2025-10-27
 */
@Service
public class CommunityServiceImpl implements ICommunityService
{
    @Autowired
    private CommunityMapper communityMapper;

    @Autowired
    private BuildingMapper buildingMapper;

    @Autowired
    private HouseMapper houseMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private ParkingSpaceMapper parkingSpaceMapper;

    @Autowired
    private StorageRoomMapper storageRoomMapper;

    /**
     * 查询项目管理
     * 
     * @param communityId 项目管理主键
     * @return 项目管理
     */
    @Override
    public Community selectCommunityByCommunityId(Long communityId)
    {
        return communityMapper.selectCommunityByCommunityId(communityId);
    }

    /**
     * 查询项目管理列表
     * 
     * @param community 项目管理
     * @return 项目管理
     */
    @Override
    public List<Community> selectCommunityList(Community community)
    {
        return communityMapper.selectCommunityList(community);
    }

    /**
     * 新增项目管理
     * 
     * @param community 项目管理
     * @return 结果
     */
    @Override
    public int insertCommunity(Community community)
    {
        community.setCreateTime(DateUtils.getNowDate());
        return communityMapper.insertCommunity(community);
    }

    /**
     * 修改项目管理
     * 
     * @param community 项目管理
     * @return 结果
     */
    @Override
    public int updateCommunity(Community community)
    {
        community.setUpdateTime(DateUtils.getNowDate());
        return communityMapper.updateCommunity(community);
    }

    /**
     * 批量删除项目管理
     * 
     * @param communityIds 需要删除的项目管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCommunityByCommunityIds(Long[] communityIds)
    {
        buildingMapper.deleteBuildingByBuildingIds(communityIds);
        houseMapper.deleteHouseByHouseIds(communityIds);
        shopMapper.deleteShopByShopIds(communityIds);
        parkingSpaceMapper.deleteParkingSpaceByParkingSpaceIds(communityIds);
        storageRoomMapper.deleteStorageRoomByStorageRoomIds(communityIds);
        return communityMapper.deleteCommunityByCommunityIds(communityIds);
    }

    /**
     * 删除项目管理信息
     * 
     * @param communityId 项目管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCommunityByCommunityId(Long communityId)
    {
        buildingMapper.deleteBuildingByBuildingId(communityId);
        houseMapper.deleteHouseByHouseId(communityId);
        shopMapper.deleteShopByShopId(communityId);
        parkingSpaceMapper.deleteParkingSpaceByParkingSpaceId(communityId);
        storageRoomMapper.deleteStorageRoomByStorageRoomId(communityId);
        return communityMapper.deleteCommunityByCommunityId(communityId);
    }

    /**
     * 导入文件的对象
     * @param communityList
     * @return
     */
    @Override
    public int importCommunityList(List<Community> communityList) {
        communityList.stream().forEach(community -> {
            //为每个社区对象设置创建的时间
            community.setCreateTime(DateUtils.getNowDate());
            //调用mapper插入数据
            communityMapper.insertCommunity(community);
        });

        //返回导入成功的条数信息
        return communityList.size();
    }

    @Override
    public Long count() {
        return communityMapper.count();
    }
}
